package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhDzzs;
import com.ruoyi.dzzh.service.IDzzhDzzsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地灾知识Controller
 * 
 * @author cjt
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/dzzh/dzzs")
public class DzzhDzzsController extends BaseController
{
    @Autowired
    private IDzzhDzzsService dzzhDzzsService;

    /**
     * 查询地灾知识列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:dzzs:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhDzzs dzzhDzzs)
    {
        startPage();
        List<DzzhDzzs> list = dzzhDzzsService.selectDzzhDzzsList(dzzhDzzs);
        return getDataTable(list);
    }

    /**
     * 导出地灾知识列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:dzzs:export')")
    @Log(title = "地灾知识", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhDzzs dzzhDzzs)
    {
        List<DzzhDzzs> list = dzzhDzzsService.selectDzzhDzzsList(dzzhDzzs);
        ExcelUtil<DzzhDzzs> util = new ExcelUtil<DzzhDzzs>(DzzhDzzs.class);
        util.exportExcel(response, list, "地灾知识数据");
    }

    /**
     * 获取地灾知识详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:dzzs:query')")
    @GetMapping(value = "/{dzzsId}")
    public AjaxResult getInfo(@PathVariable("dzzsId") Long dzzsId)
    {
        return AjaxResult.success(dzzhDzzsService.selectDzzhDzzsByDzzsId(dzzsId));
    }

    /**
     * 新增地灾知识
     */
    @PreAuthorize("@ss.hasPermi('dzzh:dzzs:add')")
    @Log(title = "地灾知识", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhDzzs dzzhDzzs)
    {
        return toAjax(dzzhDzzsService.insertDzzhDzzs(dzzhDzzs));
    }

    /**
     * 修改地灾知识
     */
    @PreAuthorize("@ss.hasPermi('dzzh:dzzs:edit')")
    @Log(title = "地灾知识", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhDzzs dzzhDzzs)
    {
        return toAjax(dzzhDzzsService.updateDzzhDzzs(dzzhDzzs));
    }

    /**
     * 删除地灾知识
     */
    @PreAuthorize("@ss.hasPermi('dzzh:dzzs:remove')")
    @Log(title = "地灾知识", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dzzsIds}")
    public AjaxResult remove(@PathVariable Long[] dzzsIds)
    {
        return toAjax(dzzhDzzsService.deleteDzzhDzzsByDzzsIds(dzzsIds));
    }
}
